package com.lzj.demo.design.builder;

import com.lzj.demo.design.builder.matter.ceiling.LevelOneCeiling;
import com.lzj.demo.design.builder.matter.ceiling.LevelTwoCeiling;
import com.lzj.demo.design.builder.matter.coat.DuluxCoat;
import com.lzj.demo.design.builder.matter.coat.LiBangCoat;
import com.lzj.demo.design.builder.matter.floor.ShengXiangFloor;
import com.lzj.demo.design.builder.matter.Matter;
import com.lzj.demo.design.builder.matter.title.DongPengTitle;
import com.lzj.demo.design.builder.matter.title.MarcoPoloTitle;
import com.lzj.demo.design.common.DemoConstant;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 房屋面积（area）、装修等级（level），根据不同类型的装修等级选择不同的材料。
 * 其次，在实现过程中可以看到每一段if代码块中包含着不同的材料（吊顶为二级顶；涂料为立邦；地砖为马可波罗），
 * 最终生成装修清单和装修价格。最后，提供获取装修详细信息的方法，返回给调用方，便于客户了解装修清单。
 * */
@Slf4j
public class MenuServiceImpl {
    /**
     * 传统的if-else写法
     * */
    public String getMatterList(BigDecimal area,Integer level){
        List<Matter> matterList = new ArrayList<>();
        BigDecimal price =  BigDecimal.ZERO;
        //豪华欧式
        if(level == DemoConstant.ONE){
            //一级吊顶
            LevelTwoCeiling levelTwoCeiling = new LevelTwoCeiling();
            //多乐士涂料
            DuluxCoat duluxCoat = new DuluxCoat();
            //圣象地板
            ShengXiangFloor shengXiangFloor = new ShengXiangFloor();
            //组合材料
            matterList.add(levelTwoCeiling);
            matterList.add(duluxCoat);
            matterList.add(shengXiangFloor);
            //计算造价
            price = price.add(area.multiply(new BigDecimal("0.2").multiply(levelTwoCeiling.price())));
            price = price.add(area.multiply(new BigDecimal("1.4").multiply(duluxCoat.price())));
            price = price.add(area.multiply(shengXiangFloor.price()));
        }
        //轻奢田园
        if(level == DemoConstant.TWO){
            LevelTwoCeiling levelTwoCeiling = new LevelTwoCeiling();
            LiBangCoat liBangCoat = new LiBangCoat();
            MarcoPoloTitle marcoPoloTitle = new MarcoPoloTitle();
            matterList.add(levelTwoCeiling);
            matterList.add(liBangCoat);
            matterList.add(marcoPoloTitle);
            price = price.add(area.multiply(new BigDecimal("0.2").multiply(levelTwoCeiling.price())));
            price = price.add(area.multiply(new BigDecimal("1.4").multiply(liBangCoat.price())));
            price = price.add(area.multiply(marcoPoloTitle.price()));
        }
        //现代简约
        if(level == DemoConstant.THREE){
            LevelOneCeiling levelOneCeiling = new LevelOneCeiling();
            LiBangCoat liBangCoat = new LiBangCoat();
            DongPengTitle dongPengTitle = new DongPengTitle();
            matterList.add(levelOneCeiling);
            matterList.add(liBangCoat);
            matterList.add(dongPengTitle);
            price = price.add(area.multiply(new BigDecimal("0.2").multiply(levelOneCeiling.price())));
            price = price.add(area.multiply(new BigDecimal("1.4").multiply(liBangCoat.price())));
            price = price.add(area.multiply(dongPengTitle.price()));
        }
        StringBuilder sb = new StringBuilder();
        sb.append("\r\n ------------------------------------\r\n");
        sb.append("装修清单").append("\r\n");
        sb.append("装修等级：").append(level).append("\r\n");
        sb.append("装修价格：").append(price.setScale(2,BigDecimal.ROUND_HALF_UP)).append("元\r\n");
        sb.append("房屋面积：").append(area.doubleValue()).append("平方米\r\n");
        sb.append("材料清单：\r\n");
        matterList.forEach(matter-> sb.append(matter.scene()).append(": ").append(matter.brand()).append("、")
                .append(matter.model()).append("、每平方米价格").append(matter.price()).append("元 \r\n"));
        return sb.toString();
    }
}
